<template>
  <div o-Container>
    <o-list v-bind:source="list.berth"
            v-bind="{created:create,exported:output,modified:modify,searched:search}"/>
    <o-dialog v-bind:source="panel" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.berth" v-bind="{saved:save,backed:back}"></o-item>
      </template>
    </o-dialog>
  </div>
</template>

<script>
  export default {
    name: "mms_cus_berth_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        list: {
          berth: {
            data: {
              id: 9,
              cellData: [
                {name: "CompanyID", searchKey: "=", width: 140},//小区
                {
                  name: "ProjectID", filterKey: "=",
                  searchKey: "=", width: 170,
                  link: [{binding: "CompanyID", mapping: "CompanyID"}]
                },//过滤小区
                {name: "AreaID", width: 200, searchKey: "=", link: [{binding: "ProjectID", mapping: "ProjectID"}]},//站点 搜索
                {name: "BuildingID", width: 170, searchKey: "=", link: [{binding: "AreaID", mapping: "AreaID"}]},//站点 搜索
                // {name: "FloorID", width: 80, searchKey: "=", link: [{binding: "BuildingID", mapping: "BuildingID"}]},//楼层id 根据站点来筛选楼层
                {name: "FloorID"},//楼层id 根据站点来筛选楼层
                {name: "Code", width: 100, searchKey: "LIKE"},//编码
                {name: "UniqueCode", width: 270, searchKey: "LIKE"},//编码
                {name: "Name", width: 130, searchKey: "LIKE"},//名称
                {name: "ProprietorID", width: 200, searchKey: "=", link: [{binding: "ProjectID", mapping: "ProjectID"}]},
                {name: "PropertyID", width: 100,},	  // 属性
                {name: "ContractId", width: 100},	// 合同
                {name: "TypeID"},// 1:公区；2:铺位；3:班级；
                {name: "LevelID", searchKey: "="},// 级别：铺位低端、高端；1年级、2年级
                {name: "Area"},//面积
                // {name: "Note", width: 200},
                {name: "CreateTime", width: 150},//创建时间
              ],
            }
          },
        },
        item: {
          berth: {
            data: {
              id: 186,
              cellData: [
                {name: "ProjectID"},//楼层id
                {name: "FloorID", link: [{binding: "ProjectID", mapping: "ProjectID"}]},//楼层id
                // {name: "ProprietorID"},// 所属业主
                {name: "ProprietorID", link: [{binding: "ProjectID", mapping: "ProjectID"}]},// 所属业主
                {name: "Name"},//铺位名称
                {name: "TypeID"},// 1:公区；2:铺位；3:班级；
                {name: "Code"},//铺位编码
                {name: "UniqueCode"},//铺位编码
                {name: "LevelID"},// 级别：铺位低端、高端；1年级、2年级
                {name: "ContractId"},	// 合同
                {name: "Signatory"},	// 招商人员
                {name: "SigningDate"},	// 招商日期
                {name: "PropertyID"},	// 铺位属性
                {name: "Status"},	// 租售状态
                {name: "Area"},//楼层面积
                // {name: "ElectricityPriceID", link: [{binding: "ProjectID", mapping: "ProjectID"}]},// 电价
                // {name: "WaterPriceID", link: [{mapping: "ProjectID", value: this.$parent.octopus.passport.project}]},// 水价
                // {name: "GasPriceID", link: [{mapping: "ProjectID", value: this.$parent.octopus.passport.project}]},// 气价
                {name: "CreateTime"},//创建时间
                {name: "Note"},
                {name: "PhotoData"},//创建时间
              ]
            },
          },
        },
        panel: {
          visible: false,
        },
      }
    },
    created: function () {
      this.init();
    },
    methods: {
      init: function () {
        let url = this.octopus.vue.$route.path;
        // MMS
        if (url.indexOf("MMS/Project/Berth/List") > -1) {
          // this.octopus.tools.parseCell(this.item.berth.data, "ProprietorID").link = null;
          // this.octopus.tools.parseCell(this.item.berth.data, "ElectricityPriceID").link = null;
        }
        // MDM
        else {
          // alert(this.octopus.passport.authorization.company);
          this.octopus.tools.parseCell(this.list.berth.data, "CompanyID").show = false;
          // this.octopus.tools.parseCell(this.list.berth.data, "CompanyID").searchKey = null;
          // this.octopus.tools.parseCell(this.list.berth.data, "CompanyID").filterValue = this.octopus.passport.authorization.company;
          this.octopus.tools.parseCell(this.list.berth.data, "ProjectID").show = false;
          this.octopus.tools.parseCell(this.list.berth.data, "ProjectID").filterValue = this.octopus.passport.project;
          // this.octopus.tools.parseCell(this.list.berth.data, "ProjectID").link = null;
          this.octopus.tools.parseCell(this.list.berth.data, "AreaID").link = [{
            mapping: "ProjectID",
            value: this.octopus.passport.project
          }];

          // this.octopus.tools.parseCell(this.list.berth.data, "BuildingID").link = [{
          //   mapping: "ProjectID",
          //   value: this.octopus.passport.project
          // }];


          // 配置模式下 只能选择当前项目下的租户/业主。
          this.octopus.tools.parseCell(this.item.berth.data, "ProjectID").link = [{
            mapping: "CompanyID",
            value: this.octopus.passport.authorization.company
          }];
          // this.octopus.tools.parseCell(this.item.berth.data, "FloorID").link = [{
          //   mapping: "ProjectID",
          //   value: this.octopus.passport.project
          // }];
          this.octopus.tools.parseCell(this.item.berth.data, "ProprietorID").link = [{
            mapping: "CompanyID",
            value: this.octopus.passport.authorization.company
          }];
        }
      },
      create: function () {
        this.item.berth.data.value = null;
        this.item.berth.control.load();//新增没有数据加载
        this.panel.visible = true;
      },
      output: function (data) {
        this.octopus.tips.success("下载完成。");
        // 导出以后，回调这里给客户端操作。
        // 核心思想是cellData包含search数据（不管有没有），回传以后发送export指令，后台api会直接返回导出的数据提供下载。
      },
      search: function (cell) {
      },
      modify: function (row) {//编辑
        this.item.berth.data.value = row.ID;
        this.item.berth.control.load();//编辑根据行id请求数据；然后加载
        this.panel.visible = true;
      },
      del: function (row) {
        alert("del key: " + JSON.stringify(row));
      },
      save: function (data) {
        this.octopus.tips.success(data);
        // 刷新list
        this.list.berth.control.load();
        this.back();
      },
      back: function () {
        this.panel.visible = false;
      }
    },
    props: ["oData"]
  }
</script>
